/*
 * 触发类
 * */

$(document).ready(
    function () {

        /**
         * 截取url
         * @returns {Object}
         * @constructor
         */
        function GetRequest() {
            var url = location.search; //获取url中"?"符后的字串
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
                }
            }
            return theRequest;
        }

        var Request = new Object();
        Request = GetRequest();

        // 获取主机地址之后的目录
        var curWwwPath = window.document.location.href;

        /**
         * 获取项目根路径
         *
         * @returns {string} 返回路径地址
         */
        function getRootPath() {
            return "http://127.0.0.1";
        }

        //判断是否是修改信息页面
        var isUpContent = curWwwPath.indexOf("manager/updateContent.html");
        if (isUpContent > 0) {
            $.ajax({
                type: "POST",
                async: false,
                url: getRootPath() + "/manager/queryArticle.do",
                data: "quId=" + Request["id"],
                success: function (data) {
                    //会话超时判断
                    if (data.length == 73) {
                        alert("会话已超时");
                        document.location = 'signin.html';
                    }
                    if (data.status == 1) {
                        var article = data.data.Article;
                        var resource = data.data.Resource;
                        $("#updateContentNameId").val(article.titleName);
                        $("#sortingId").val(article.sorting);
                        $("#isUse").val(article.thisState);
                        $("#upEditor1").val(article.content);
                        $("#upEditor2").val(article.detailed);
                        $("#imageSortingId").val(resource.sorting);
                    }
                }
            });
        }

        //判断是否是修改资源页面
        var isUpResource = curWwwPath.indexOf("manager/updateResource.html");
        if (isUpResource > 0) {
            $.ajax({
                type: "POST",
                async: false,
                url: getRootPath() + "/manager/queryResource.do",
                data: "resourceId=" + Request["id"],
                success: function (data) {
                    //会话超时判断
                    if (data.length == 73) {
                        alert("会话已超时");
                        document.location = 'signin.html';
                    }
                    if (data.status == 1) {
                        $("#resourceName").val(data.data.name);
                        $("#resourceSorting").val(data.data.sorting);
                        $("#resourceState").val(data.data.state);
                    }
                }
            });
        }


    });